#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Create by zhang
# Create on 2022/6/27 21:54
from typing import List
from pdfplumber.page import Page

from domain.report.common.task_status import TaskStatusEnum


class TaskData:
    def __init__(self, name: str):
        self.name: str = name
        self.data:dict = dict()
        self.status: TaskStatusEnum = TaskStatusEnum.WAIT
        self.data[name] = list()

    def start(self):
        self.status = TaskStatusEnum.START

    def finish(self):
        self.status = TaskStatusEnum.FINISH

    def set(self, name:str, value):
        self.data[name] = value

    def get(self, name:str, default=None):
        return self.data.get(name, default)


class Request:
    def __init__(self):
        self.history:List[Page] = list()
        self.data:dict = dict()

    def add_page(self, page:Page):
        self.history.append(page)
        return self

    def current_page(self) -> Page:
        return self.history[-1]

    def add_data(self, item:TaskData):
        self.data[item.name] = item

    def get_data(self, item:TaskData):
        return self.data.get(item.name)
